<?php
namespace app\admin\controller;
use app\admin\logic\IndexLogic;
use app\common\model\User;
use app\common\model\UserInfo;
use app\common\model\UserCredit;
use app\common\model\Order;
use app\common\model\Volunteer;
use app\common\model\Practice;
use app\common\model\SiteTeam;
use app\common\model\Message;
use app\vehicle\model\Site;
use app\vehicle\logic\TplLogic;
use think\Controller;
class Test extends Controller{
    public function __construct()
    {
        parent::__construct();
    }
    public function ttt(){
        $list = db('user_integral_log')->where('practice_id','>',0)->where('status','=',0)->limit(150)->select();
        foreach($list as $k=>$v){
            $num = db('practice_log')->where('user_id','=',$v['user_id'])->where('aid','=',$v['practice_id'])->value('volunteer');
            db('user_integral_log')->where('id','=',$v['id'])->update(['status'=>1]);
            if($num==1){
                db('user')->where('id','=',$v['user_id'])->setInc('duration2',$v['integral']/2);
            }else{
                db('user')->where('id','=',$v['user_id'])->setInc('duration3',$v['integral']);
            }
        }
        echo 'success';
    }
    public function bing_site(){
        $oid = $_SESSION['xm_travel']['admin_info']['oid'];
        echo 123;arr($_SESSION);echo $oid;die;
        $site = db('site')->select();
        $this->assign('site',$site);
        return $this->fetch();
    }
    public function check_info(){
        $time = time()-86400*6;
        $userx = '';
        $usery = '';
        $volunteery = '';
        for($i=0;$i<7;$i++){
            $t = $time+$i*86400;
            $s_time = strtotime(date('Y-m-d',$t));
            $userx.=','.date('m/d',$t);
            $usery.=','.db('user_login')->where('add_time','>=',$s_time)->where('add_time','<',$s_time+86400)->group('uid')->count();
            $volunteery.=','.db('volunteer')->where('create_time','>=',$s_time)->where('create_time','<',$s_time+86400)->count();;
        }
        $wish[] = db('wish')->where('status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',1)->count();
        return json(['userx'=>ltrim($userx,','),'usery'=>ltrim($usery,','),'volunteery'=>ltrim($volunteery,','),'wish'=>$wish]);
    }

    public function check_num(){
        $num = db('volunteer')->count()+20000;
        $count[] = db('site_team')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('o_status','=',0)->count();
        $count[] = db('practice')->where('status','=',0)->count();
        $count[] = db('user')->count()+20000;
        $count[] = db('article')->count();
        $count[] = db('practice')->count();
        $count[] = db('forum')->count();


        $site_list = db('site_team')->limit(6)->order('number desc')->select();
        $nums = $site_list[0]['number'];
        foreach($site_list as $k=>$v){
            $site_list[$k]['bai'] = round($v['number']/$nums*100);
        }
        $num1 = db('site')->count()+632;
        $num2 = db('site_team')->count()+14;
        return json(['data'=>$num,'data1'=>$num1,'data2'=>$num2,'count'=>$count,'site_list'=>$site_list]);
    }
    public function site(){
        $type = input('type');
        if($type==1){
            $site_list = db('site')->where('cate_id','=',2)->limit(10)->order('number desc')->select();
        }else if($type==2){
            $site_list = db('site')->where('cate_id','=',1)->limit(10)->order('number desc')->select();
        }else if($type==3){
            $site_list = db('site_team')->limit(10)->order('number desc')->select();
        }

        $num = $site_list[0]['number'];
        foreach($site_list as $k=>$v){
            $site_list[$k]['bai'] = round($v['number']/$num*100);
        }
        $this->assign('site_list',$site_list);
        return $this->fetch('index/site');
    }
    public function site1(){
        $type = input('type');
        if($type==1){
            $site_list = db('site')->where('cate_id','=',2)->limit(10)->order('number desc')->select();
        }else if($type==2){
            $site_list = db('site')->where('cate_id','=',1)->limit(10)->order('number desc')->select();
        }else if($type==3){
            $site_list = db('site_team')->limit(10)->order('number desc')->select();
        }

        $num = $site_list[0]['number'];
        foreach($site_list as $k=>$v){
            $site_list[$k]['bai'] = round($v['number']/$num*100);
        }
        $this->assign('site_list',$site_list);
        return $this->fetch('index/site1');
    }
    public function home(){
        $count[] = db('site_team')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('o_status','=',0)->count();
        $count[] = db('practice')->where('status','=',0)->count();
        $count[] = db('user')->count()+22000;
        $count[] = db('article')->count()+146;
        $count[] = db('practice')->count();
        $count[] = db('forum')->count()+30;
        $count[] = db('user')->count()+ 21846;
        $count[] = db('article')->count()+143;
        $count[] = db('practice')->count();
        $count[] = db('forum')->count()+27;
        $this->assign('count',$count);
        $site_list = db('site_team')->limit(6)->order('number desc')->select();
        $num = $site_list[0]['number'];
        foreach($site_list as $k=>$v){
            $site_list[$k]['bai'] = round($v['number']/$num*100);
        }
        $this->assign('site_list',$site_list);
        $wish[] = db('wish')->where('status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',1)->count();
        $this->assign('wish',$wish);
        $num = db('volunteer')->count();
        $this->assign('num', $num);
        $time = time()-86400*6;
        $userx = '';
        $usery = '';
        $volunteery = '';
        for($i=0;$i<7;$i++){
            $t = $time+$i*86400;
            $s_time = strtotime(date('Y-m-d',$t));
            $userx.=','.date('m/d',$t);
            $usery.=','.db('user_login')->where('add_time','>=',$s_time)->where('add_time','<',$s_time+86400)->group('uid')->count();
            $volunteery.=','.db('volunteer')->where('create_time','>=',$s_time)->where('create_time','<',$s_time+86400)->count();;
        }
        $this->assign('userx', ltrim($userx,','));
        $this->assign('usery', ltrim($usery,','));
        $this->assign('volunteery', ltrim($volunteery,','));
        return $this->fetch('index/index3');
    }
    public function home1(){
        $count[] = db('site_team')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('status','=',0)->count();
        $count[] = db('volunteer')->where('o_status','=',0)->count();
        $count[] = db('practice')->where('status','=',0)->count();
        $count[] = db('user')->count()+22000;
        $count[] = db('article')->count()+146;
        $count[] = db('practice')->count();
        $count[] = db('forum')->count()+30;
        $count[] = db('user')->count();
        $count[] = db('article')->count();
        $count[] = db('practice')->count();
        $count[] = db('forum')->count();
        $this->assign('count',$count);
        $site_list = db('site_team')->limit(6)->order('number desc')->select();
        $num = $site_list[0]['number'];
        foreach($site_list as $k=>$v){
            $site_list[$k]['bai'] = round($v['number']/$num*100);
        }
        $this->assign('site_list',$site_list);
        $wish[] = db('wish')->where('status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',0)->count();
        $wish[] = db('wish')->where('status','=',1)->where('order_status','=',1)->count();
        $this->assign('wish',$wish);
        $num = db('volunteer')->count();
        $this->assign('num', $num);
        $time = time()-86400*6;
        $userx = '';
        $usery = '';
        $volunteery = '';
        for($i=0;$i<7;$i++){
            $t = $time+$i*86400;
            $s_time = strtotime(date('Y-m-d',$t));
            $userx.=','.date('m/d',$t);
            $usery.=','.db('user_login')->where('add_time','>=',$s_time)->where('add_time','<',$s_time+86400)->group('uid')->count();
            $volunteery.=','.db('volunteer')->where('create_time','>=',$s_time)->where('create_time','<',$s_time+86400)->count();;
        }
        $this->assign('userx', ltrim($userx,','));
        $this->assign('usery', ltrim($usery,','));
        $this->assign('volunteery', ltrim($volunteery,','));
        return $this->fetch('index/index3');
    }
}